package com.example.farmer.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.farmer.Adapter.Class.SearchAdapter; // 确保包路径正确
import com.example.farmer.Entity.ProductInfo;
import com.example.farmer.R;

import java.util.ArrayList;
import java.util.List;

public class SearchActivity extends AppCompatActivity {

    private EditText searchEditText;
    private Button searchButton;
    private RecyclerView searchRecyclerView;
    private List<ProductInfo> productList; // 完整的商品列表
    private SearchAdapter searchAdapter; // 定义搜索适配器
    private List<String> searchResults; // 定义搜索结果列表

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sousuo);

        searchEditText = findViewById(R.id.searchEditText);
        searchButton = findViewById(R.id.searchButton);
        searchRecyclerView = findViewById(R.id.searchRecyclerView);

        // 初始化搜索结果列表和适配器
        searchResults = new ArrayList<>();
        searchAdapter = new SearchAdapter(searchResults);

        searchButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String query = searchEditText.getText().toString();
                performSearch(query);
            }
        });

        // 设置 RecyclerView 的适配器和布局管理器
        searchRecyclerView.setAdapter(searchAdapter);
        searchRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    }

    private void performSearch(String query) {
        // 根据查询过滤商品列表
        searchResults.clear();

    }
}